// Helper javascript pour l'ajout d'un adhérent
// auteur : Sebastian Mosser

// Ajout des calendriers
addCalendar("BirthDateCal","Date de Naissance","birthDate", "addMember");

addCalendar("EntryDateCal","Entrée au club","entryDate", "addMember");



function updateBirthCity() {
	var birthZip = document.getElementById("birthZip").value;
	if (birthZip != "FOREIGN" && birthZip.length != 5)
		return displayBirthCity('<option value="-1"> Inconnue </option>');
		
	var param = new Array();
	param[0] = birthZip;
	
	invoke(1,"City","getAsList",param, displayBirthCity);
}

function displayBirthCity(text) {
	var cityList = '<select name="birthCity" class="edit">';
	if (text == "")
		text = '<option value="-1"> Inconnue </option>';
	cityList += text;
	cityList += "</ select>";
	setBirthCity(cityList);
}

function setBirthCity(text) {
	document.getElementById("cityList").innerHTML = text;
}


function foreignBirthCity() {
  var birthInputSpan =  document.getElementById("birthZipCode");
  var birthZip = document.getElementById("birthZip");
  
  var newInput = '';
  
  if (birthZip.value == "FOREIGN") {
  	newInput += '<input type="text" name="birthZip" id="birthZip" class="edit" onblur="updateBirthCity();" />'
  
  }
  else {
	  newInput += '<input type="hidden" name="birthZip" id="birthZip" value="FOREIGN" />';
  	newInput += '<input type="text" name="na" disabled="yes" value="Etranger" class="edit" />'
	}
	
	birthInputSpan.innerHTML = newInput;
	
	updateBirthCity();

}


function updateLivingCity() {
	var livingZip = document.getElementById("livingZip").value;
	
	if (livingZip.length != 5)
		return displayLivingCity('<option value="-1"> Inconnue </option>');
		
	var param = new Array();
	param[0] = livingZip;
	
	invoke(2,"City","getAsList",param, displayLivingCity);
}

function displayLivingCity(text) {
	var cityList = '<select name="livingCity" class="edit">';
	if (text == "")
		text = '<option value="-1"> Inconnue </option>';
	cityList += text;
	cityList += "</ select>";
	setLivingCity(cityList);
}

function setLivingCity(text) {
	document.getElementById("livingCityList").innerHTML = text;
}


function updateMoney() {
	var cotis = document.getElementById("cotisation");
	if (cotis.value == "-1") {
		var na = '<input class="edit" type="text" value="Non Approprié" disabled="yes" /> ';
		document.getElementById("moneyTypeList").innerHTML = na;
	}
	else {
		var param = new Array();
		if (document.getElementById("moneyType")) 
			param[0] = document.getElementById("moneyType").value
			
		invoke(3,"MoneyType","getAsList",param, setMoneyType);
	}
}

function setMoneyType(text) {
	var ans = '<select name="moneyType" class="edit">';
	ans += text;
	ans += '</select>';
	document.getElementById("moneyTypeList").innerHTML = ans;
}


function displayMember(memberId) {
	var param = new Array();
	param[0] = memberId;
	invoke(4,"Member", "display", param, showMember);
}


function showMember(text) {
	document.getElementById("duplicateMember").innerHTML = text;
}

function toggleHelp() {
	var helpDiv = document.getElementById("onlineHelp");
	if (helpDiv.style.display == "none")
		helpDiv.style.display = '';
	else
		helpDiv.style.display = 'none';
}